%% Select local grid
idtemp=str2double(getenv('SGE_TASK_ID'));
if idtemp<workers
   u0grid_local=u0grid(jobs*(idtemp-1)+1: idtemp*jobs,:);
   u1grid_local=u1grid(jobs*(idtemp-1)+1: idtemp*jobs,:);
   u2grid_local=u2grid(jobs*(idtemp-1)+1: idtemp*jobs,:);
   u3grid_local=u3grid(jobs*(idtemp-1)+1: idtemp*jobs,:);
   u4grid_local=u4grid(jobs*(idtemp-1)+1: idtemp*jobs,:);
else
   u0grid_local=u0grid(jobs*(idtemp-1)+1: end,:);
   u1grid_local=u1grid(jobs*(idtemp-1)+1: end,:);
   u2grid_local=u2grid(jobs*(idtemp-1)+1: end,:);
   u3grid_local=u3grid(jobs*(idtemp-1)+1: end,:);
   u4grid_local=u4grid(jobs*(idtemp-1)+1: end,:);
end

sg_local=size(u1grid_local,1);

%% Do the job
[sgreduced, ...
id_Ugridreduced, s_id_gridreduced, sU_id_gridreduced,...
P_col,...
Tcoord_zeros,...
Ugridreduced, n_U_sets, indices_pairs_extended, Tcoord, C, C_sign,...
cr_obsequiv, cr_one, cr_zeros,fill_obsequiv, fill_one, fill_zeros, numeqconstraints, RHS_one, RHS_zeros,...
equalorder, n_vertices,infty_pos]=useful_anyparam(u0grid_local, u1grid_local, u2grid_local, u3grid_local, u4grid_local,sg_local,random_indices_pairs) ;  


addpath /share/apps/mosek-9.2/9.2/toolbox/r2015aom

IdSetM=OneSide(u0grid_local, u1grid_local, u2grid_local, u3grid_local, u4grid_local, ...
                       sgreduced, PYX_cond_x, ...
                       id_Ugridreduced, s_id_gridreduced, sU_id_gridreduced,...
                       P_col, ...
                       Tcoord_zeros,...
                       Ugridreduced, n_U_sets, indices_pairs_extended, Tcoord, C, C_sign,...
                       cr_obsequiv, cr_one, cr_zeros,fill_obsequiv, fill_one, fill_zeros, numeqconstraints, RHS_one, RHS_zeros, equalorder,n_vertices,infty_pos);  

filename = sprintf('IdSetM.%d.mat', ID);
save(filename,'IdSetM')  
